package com.hgb.mall.mbg.mapper;

import com.hgb.mall.mbg.entity.UmsIntegrationChangeHistory;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

import javax.annotation.Generated;
import java.util.List;
import java.util.Optional;

import static com.hgb.mall.mbg.mapper.UmsIntegrationChangeHistoryDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

@Mapper
public interface UmsIntegrationChangeHistoryMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn
            .columnList(id, memberId, createTime, changeType, changeCount, operateMan, operateNote, sourceType);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(UmsIntegrationChangeHistory record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(memberId).equalTo(record::getMemberId)
                  .set(createTime).equalTo(record::getCreateTime)
                  .set(changeType).equalTo(record::getChangeType)
                  .set(changeCount).equalTo(record::getChangeCount)
                  .set(operateMan).equalTo(record::getOperateMan)
                  .set(operateNote).equalTo(record::getOperateNote)
                  .set(sourceType).equalTo(record::getSourceType);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(UmsIntegrationChangeHistory record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(memberId).equalToWhenPresent(record::getMemberId)
                  .set(createTime).equalToWhenPresent(record::getCreateTime)
                  .set(changeType).equalToWhenPresent(record::getChangeType)
                  .set(changeCount).equalToWhenPresent(record::getChangeCount)
                  .set(operateMan).equalToWhenPresent(record::getOperateMan)
                  .set(operateNote).equalToWhenPresent(record::getOperateNote)
                  .set(sourceType).equalToWhenPresent(record::getSourceType);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type = SqlProviderAdapter.class, method = "insert")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "record.id", before = false, resultType = Long.class)
    int insert(InsertStatementProvider<UmsIntegrationChangeHistory> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @ResultMap("UmsIntegrationChangeHistoryResult")
    Optional<UmsIntegrationChangeHistory> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type = SqlProviderAdapter.class, method = "select")
    @Results(id = "UmsIntegrationChangeHistoryResult", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "member_id", property = "memberId", jdbcType = JdbcType.BIGINT),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "change_type", property = "changeType", jdbcType = JdbcType.INTEGER),
            @Result(column = "change_count", property = "changeCount", jdbcType = JdbcType.INTEGER),
            @Result(column = "operate_man", property = "operateMan", jdbcType = JdbcType.VARCHAR),
            @Result(column = "operate_note", property = "operateNote", jdbcType = JdbcType.VARCHAR),
            @Result(column = "source_type", property = "sourceType", jdbcType = JdbcType.INTEGER)
    })
    List<UmsIntegrationChangeHistory> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type = SqlProviderAdapter.class, method = "update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, umsIntegrationChangeHistory, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, umsIntegrationChangeHistory, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(UmsIntegrationChangeHistory record) {
        return MyBatis3Utils.insert(this::insert, record, umsIntegrationChangeHistory, c ->
                c.map(memberId).toProperty("memberId")
                 .map(createTime).toProperty("createTime")
                 .map(changeType).toProperty("changeType")
                 .map(changeCount).toProperty("changeCount")
                 .map(operateMan).toProperty("operateMan")
                 .map(operateNote).toProperty("operateNote")
                 .map(sourceType).toProperty("sourceType")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(UmsIntegrationChangeHistory record) {
        return MyBatis3Utils.insert(this::insert, record, umsIntegrationChangeHistory, c ->
                c.map(memberId).toPropertyWhenPresent("memberId", record::getMemberId)
                 .map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
                 .map(changeType).toPropertyWhenPresent("changeType", record::getChangeType)
                 .map(changeCount).toPropertyWhenPresent("changeCount", record::getChangeCount)
                 .map(operateMan).toPropertyWhenPresent("operateMan", record::getOperateMan)
                 .map(operateNote).toPropertyWhenPresent("operateNote", record::getOperateNote)
                 .map(sourceType).toPropertyWhenPresent("sourceType", record::getSourceType)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<UmsIntegrationChangeHistory> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, umsIntegrationChangeHistory, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<UmsIntegrationChangeHistory> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, umsIntegrationChangeHistory, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<UmsIntegrationChangeHistory> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, umsIntegrationChangeHistory, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<UmsIntegrationChangeHistory> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
                c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, umsIntegrationChangeHistory, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(UmsIntegrationChangeHistory record) {
        return update(c ->
                c.set(memberId).equalTo(record::getMemberId)
                 .set(createTime).equalTo(record::getCreateTime)
                 .set(changeType).equalTo(record::getChangeType)
                 .set(changeCount).equalTo(record::getChangeCount)
                 .set(operateMan).equalTo(record::getOperateMan)
                 .set(operateNote).equalTo(record::getOperateNote)
                 .set(sourceType).equalTo(record::getSourceType)
                 .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(UmsIntegrationChangeHistory record) {
        return update(c ->
                c.set(memberId).equalToWhenPresent(record::getMemberId)
                 .set(createTime).equalToWhenPresent(record::getCreateTime)
                 .set(changeType).equalToWhenPresent(record::getChangeType)
                 .set(changeCount).equalToWhenPresent(record::getChangeCount)
                 .set(operateMan).equalToWhenPresent(record::getOperateMan)
                 .set(operateNote).equalToWhenPresent(record::getOperateNote)
                 .set(sourceType).equalToWhenPresent(record::getSourceType)
                 .where(id, isEqualTo(record::getId))
        );
    }
}
